package com.h3c.ptability.config;

import com.h3c.ptability.service.CommService;
import com.h3c.ptability.service.ManuTranscationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.ValueOperations;

import javax.annotation.Resource;

/**
 * inventory 权限控制配置
 *
 * @author szc
 * @since 2018/5/15
 */
@Slf4j
@Configuration
public class PTAuthConfiguration {

    @Value("${authentication.config.free:#{null}}")
    private String authFree;

    @Value("${jwt.config.free:#{null}}")
    private String jwtFree;

    @Value("${sso.key}")
    private String ssoKey;

    @Value("${busi.outer.applicationkey:#{'empty'}}")
    private String outerApplicationKey;

    @Value("${busi.rsa.publickey}")
    private String pmPublickey;

    @Value("${spring.application.name}")
    private String appkey;

    @Autowired
    private CommService commService;

    @Autowired
    private ManuTranscationService manuTranscationService;

    @Resource
    private ValueOperations<String, Object> valueOperations;

    @Bean
    public FilterRegistrationBean inventoryRequestFilter() {
        log.info("<<Inventory FilterRegistrationBean init");
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new com.h3c.ptability.config.PTRequestFilter(appkey, ssoKey, pmPublickey, outerApplicationKey,
                jwtFree, authFree,commService, valueOperations, manuTranscationService));
        registration.addUrlPatterns("/*");// 拦截路径
        registration.setName("InventoryRequestFilter");// 拦截器名称
        registration.setOrder(0);// 顺序
        return registration;
    }

}
